package org.example.c3;


import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * 测试happen-before的传递性
 */
@Slf4j
public class Demo1 {
    volatile static int x;
    static int y;

    public static void main(String[] args) {
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
            }

            y = 10;
            x = 30;
        }, "t1").start();

        new Thread(() -> {
            while (x != 30) {
            }
            log.info("y:{}", y);//x=30对t2可见，y=10也可见
        }, "t2").start();
    }
}
